package org.dromara.oce.controller.inner;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.oce.domain.req.UpdateAdvertiserHoursAmountReq;
import org.dromara.oce.domain.req.UpdateIaaAdvertiserHoursAmountReq;
import org.dromara.oce.service.OceAdvertiserEverydayCostService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单
 * @desc:
 * @author: hhl
 * @date：2025/6/24 18:24
 * @module 对内接口
 */
@SaIgnore
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
@Slf4j
public class TradeOrderController {

    private final OceAdvertiserEverydayCostService oceAdvertiserEverydayCostService;

    /**
     * 修改充值订单时段的充值金额
     */
    @PostMapping("/updateOrderAdvertiserHoursAmount")
    public List<Long> updateAdvertiserHoursAmount(@RequestBody List<UpdateAdvertiserHoursAmountReq> list) {
        List<Long> successList = new ArrayList<>();

        for (UpdateAdvertiserHoursAmountReq req : list) {
            Long referralLinkId = oceAdvertiserEverydayCostService.updateAdvertiserOrderAmount(req);
            successList.add(referralLinkId);
        }
        return successList;
    }

    /**
     * 修改广告时段的收益
     * @param list
     * @return
     */
    @PostMapping("/updateIaaAdvertiserHoursAmount")
    public List<Long> updateIaaAdvertiserHoursAmount(@RequestBody List<UpdateIaaAdvertiserHoursAmountReq> list) {
        List<Long> successList = new ArrayList<>();
        for (UpdateIaaAdvertiserHoursAmountReq iaaReq : list) {
            try {
                Long referralLinkId = oceAdvertiserEverydayCostService.updateAdvertiserIaaOrderAmount(iaaReq);
                successList.add(referralLinkId);
            } catch (Exception e) {
                log.info("推广链接Id={}，发生异常，{}",iaaReq.getReferralLinkId());
            }
        }
        return successList;
    }


}
